﻿using HHG.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnLineExam.Web
{
	public partial class PaperTest : System.Web.UI.Page
	{ 
		private readonly Data.EfRepository<Data.Score> _scoreRepository;
        private readonly Data.EfRepository<Data.Paper> _paperRepository;
        Data.OnlineExamEntities _ctx;

        public string PaperName { get;private set; }

		public PaperTest() {
            _ctx = new Data.OnlineExamEntities();
            _scoreRepository = new Data.EfRepository<Data.Score>(_ctx);
            _paperRepository = new Data.EfRepository<Data.Paper>(_ctx);

        }
		protected void Page_Load(object sender, EventArgs e)
		{
			var scoreId = Request.QueryString["id"].GetInt();
			if (!IsPostBack)
			{
				if(!User.Identity.Name.StartsWith("admin"))
				if (!_scoreRepository.TableNoTracking.Any(s => 
				s.ID == scoreId && s.Paper.EndExamTime <= DateTime.Now))
				{
					Response.Write("考试未结束");
					Response.End( );
                        return;
				}
                var score = _scoreRepository.GetById(scoreId);
                PaperName = _paperRepository.GetById(score.PaperID).PaperName;

            }
		}
	}
}